//
//  SelectView.m
//  ChengHuiTong
//
//  Created by ypwl on 15/11/12.
//  Copyright © 2015年 张文权. All rights reserved.
//

#import "SelectView.h"

#import "UIView+Extension.h"



@implementation SelectView


-(instancetype)initWithFrame:(CGRect)frame WithVipModel:(VipModel*)Vipmodel{
    
    self=[super initWithFrame:frame];
    
    if (self) {
        
        self.backgroundColor=[UIColor whiteColor];
        CGFloat with=frame.size.width;
        
       // CGFloat height=frame.size.height;
        
        UIImageView*headIamgeView=[[UIImageView alloc] initWithFrame:CGRectMake(15, 15, with/3.0, with/3.0)];
        
        [headIamgeView sd_setImageWithURL:[NSURL URLWithString:Vipmodel.head_img] placeholderImage:nil];
        
        headIamgeView.layer.cornerRadius=headIamgeView.width/2.0;
        
        headIamgeView.clipsToBounds=YES;
        
        [self addSubview:headIamgeView];
        
        
        UILabel*nameLabel=[[UILabel alloc] initWithFrame:CGRectMake(headIamgeView.right+5, headIamgeView.top+5, with-headIamgeView.right-5, 15)];
        
        nameLabel.font=[UIFont systemFontOfSize:13];
        
        nameLabel.textColor=UIColorFromString(@"#535353");
        
        
        
        nameLabel.attributedText=[self getMutableString:@"名字:" allString:[NSString stringWithFormat:@"名字:%@",Vipmodel.name]];
        
        [self addSubview:nameLabel];
        
        
        UILabel*zhiweiLabel=[[UILabel alloc] initWithFrame:CGRectMake(headIamgeView.right+5, nameLabel.bottom+15, nameLabel.width, 15)];
        
        zhiweiLabel.font=[UIFont systemFontOfSize:13];
        
        zhiweiLabel.textColor=UIColorFromString(@"#535353");

        
        zhiweiLabel.attributedText=[self getMutableString:@"职位:" allString:[NSString stringWithFormat:@"分机号:%@",Vipmodel.mobile]];
        
        
        [self addSubview:zhiweiLabel];
        
        UILabel*numberLabel=[[UILabel alloc] initWithFrame:CGRectMake(headIamgeView.right+5, zhiweiLabel.bottom+15, nameLabel.width, 15)];
        
        numberLabel.font=[UIFont systemFontOfSize:13];
        
        numberLabel.textColor=UIColorFromString(@"#535353");
        
        numberLabel.attributedText=[self getMutableString:@"服务热线:" allString:[NSString stringWithFormat:@"服务热线:%@",Vipmodel.tel]];
        
        [self addSubview:numberLabel];

        
        UIView*lineView=[[UIView alloc] initWithFrame:CGRectMake(15, headIamgeView.bottom+20, with-30, 0.5)];
        
        
        lineView.backgroundColor=UIColorFromString(@"#dadada");
        
        [self addSubview:lineView];
        
        UILabel*contentLabel=[[UILabel alloc] initWithFrame:CGRectMake(lineView.left, lineView.bottom+5, lineView.width, 40)];
        
        contentLabel.numberOfLines=0;
        
        contentLabel.textAlignment=1;
        
        contentLabel.font=[UIFont systemFontOfSize:14];
        
        contentLabel.textColor=UIColorFromString(@"#585858");
        
        contentLabel.text=[NSString stringWithFormat:@"确定选择%@为您的专属客服?",Vipmodel.name];
        
        [self addSubview:contentLabel];
        
        UIButton*confirmButton=[UIButton buttonWithType:UIButtonTypeCustom];
        
        confirmButton.frame=CGRectMake((with-120)/2.0, contentLabel.bottom+10, 120, 30);
        
        [confirmButton setBackgroundColor:UIColorFromString(@"#d6a232")];
        
         confirmButton.titleLabel.font=[UIFont systemFontOfSize:14];
        
        [confirmButton setTitle:@"确定" forState:UIControlStateNormal];
        
        [confirmButton addTarget:self action:@selector(myButtonClick) forControlEvents:UIControlEventTouchUpInside];
        
        [self addSubview:confirmButton];
        
        
        UIButton*cancelButton=[UIButton buttonWithType:UIButtonTypeCustom];
        
        cancelButton.frame=CGRectMake((with-120)/2.0, confirmButton.bottom+5, 120, 30);
        
        [cancelButton setBackgroundColor:[UIColor clearColor]];
        
        cancelButton.titleLabel.font=[UIFont systemFontOfSize:14];
        
        [cancelButton setTitle:@"再想想" forState:UIControlStateNormal];
        
        [cancelButton setTitleColor:UIColorFromString(@"#a9a9a9") forState:0];
        
        
        [cancelButton addTarget:self action:@selector(entrustButtonClick) forControlEvents:UIControlEventTouchUpInside];
        
        [self addSubview:cancelButton];

        
        
        
        
    }
    
    return self;
    
}

- (instancetype)initWithFrame:(CGRect)frame isEntrust:(BOOL)isEntrust{
    
    self=[super initWithFrame:frame];
    
    if (self) {
        
        _isEntrust=isEntrust;
        
        self.backgroundColor=[UIColor clearColor];
        
        UIImageView*imageView=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.width, self.height)];
        
       
        
        imageView.image=[UIImage imageNamed:@"3_bg5_"];
        
        imageView.userInteractionEnabled=YES;
        
        [self addSubview:imageView];
        
        
        
        UIButton*myButton=[UIButton buttonWithType:UIButtonTypeCustom];
        
        myButton.frame=CGRectMake(40, self.height*0.24+10, self.width-80, 40);
       
        [myButton setTitleColor:UIColorFromString(@"#8690ef") forState:UIControlStateNormal];
        
        myButton.titleLabel.font=[UIFont systemFontOfSize:15];
        
        [myButton addTarget:self action:@selector(myButtonClick) forControlEvents:UIControlEventTouchUpInside];
        
        [imageView addSubview:myButton];
        
        UILabel*mylabel=[[UILabel alloc] initWithFrame:CGRectMake(40, myButton.top, 20,20)];
        
       // mylabel.right=myButton.left-15;
        
        mylabel.centerY=myButton.centerY;
        
        mylabel.text=@"普";
        
        mylabel.font=[UIFont systemFontOfSize:14];
        
        mylabel.textColor=UIColorFromString(@"#8690ef");
        
        mylabel.layer.borderWidth=0.5;
        
        mylabel.layer.cornerRadius=10;
        
        mylabel.textAlignment=1;
        
        mylabel.layer.borderColor=UIColorFromString(@"#8690ef").CGColor;
        
        mylabel.clipsToBounds=YES;
        
        [imageView addSubview:mylabel];
        
        UIView*lineView=[[UIView alloc] initWithFrame:CGRectMake(15, myButton.bottom+4.25, self.width-30, 0.5)];
        
        lineView.backgroundColor=[UIColor lightGrayColor];
        
        [imageView addSubview:lineView];
        
        
        UIButton*entrustButton=[UIButton buttonWithType:UIButtonTypeCustom];
        
        entrustButton.frame=CGRectMake(myButton.left, myButton.bottom+10, myButton.width, myButton.height);
        
        [entrustButton setTitleColor:UIColorFromString(@"#fd916a") forState:UIControlStateNormal];
        
        entrustButton.titleLabel.font=[UIFont systemFontOfSize:15];
        
        [entrustButton addTarget:self action:@selector(entrustButtonClick) forControlEvents:UIControlEventTouchUpInside];
        
        UILabel*titleLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.width, self.height*0.24)];
        
        titleLabel.textColor=[UIColor whiteColor];
        
        titleLabel.font=[UIFont boldSystemFontOfSize:18];
        
        titleLabel.textAlignment=1;
        
        [imageView addSubview:titleLabel];
        
        
        if (_isEntrust) {
            
            titleLabel.text=@"充值";
            
            [myButton setTitle:@"普通账户充值" forState:UIControlStateNormal];
            
            [entrustButton setTitle:@"托管账户充值" forState:UIControlStateNormal];
            
        }else{
            
                titleLabel.text=@"提现";
            
            [myButton setTitle:@"普通账户提现" forState:UIControlStateNormal];
            
            [entrustButton setTitle:@"托管账户提现" forState:UIControlStateNormal];
            
        }
        
        
        
        [imageView addSubview:entrustButton];
        
        
        UILabel*entrustlabel=[[UILabel alloc] initWithFrame:CGRectMake(40, entrustButton.top, 20, 20)];
        
        entrustlabel.centerY=entrustButton.centerY;
        
        entrustlabel.font=[UIFont systemFontOfSize:14];
        
        entrustlabel.text=@"托";
        
        entrustlabel.textColor=UIColorFromString(@"#fe916a");
        
        entrustlabel.layer.cornerRadius=10;
        
        entrustlabel.layer.borderWidth=0.5;
        
        entrustlabel.textAlignment=1;
        
        entrustlabel.layer.borderColor=UIColorFromString(@"#fe916a").CGColor;
        
        entrustlabel.clipsToBounds=YES;
        
        [imageView addSubview:entrustlabel];

        
        
    }
    
    return self;
    
    
}


- (void)myButtonClick{
    
    if (self.myButtonClickBlock) {
        
        self.myButtonClickBlock();
        
    }
    
    
}


- (void)entrustButtonClick{
    
    if (self.entrustButtonClickBlock) {
        
        self.entrustButtonClickBlock();
        
    }
    
    
}



+(UIView*)footViewWithheight:(CGFloat)height{
    
    UIView*footView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH,height)];
    
    
    UILabel*label=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 20)];
    
    label.center=footView.center;
    
    label.textColor=UIColorFromString(@"#b5b5b5");
    
    label.text=@"暂无数据";
    
    label.textAlignment=1;
    
    [footView addSubview:label];
    
    
    
    UIImageView*imageView=[[UIImageView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH/2.0)-40, label.top-100, 80, 80)];
    
    imageView.image=[UIImage imageNamed:@"foot"];
    
    
    [footView addSubview:imageView];
    
    
    return footView;
    
    
}

-(NSMutableAttributedString*)getMutableString:(NSString*)changeString allString:(NSString*)allString{
    
    NSMutableAttributedString*newString=[[NSMutableAttributedString alloc] initWithString:allString];
    
    NSUInteger Num=changeString.length;
    
    UIColor*color;
    
    
        color=UIColorFromString(@"#9f9f9f");
        
    
    

    [newString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:13] range:NSMakeRange(0, Num)];
    
    [newString addAttribute:NSForegroundColorAttributeName value:color range:NSMakeRange(0, Num)];
    
    return newString;
    
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
